/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : pop_certify.js
*  Description  : 실명인증 
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-05-08  김효순    Created.  
*  2012-05-08  김효순    Complete.  
*******************************************************************************/

jQuery(function($){
	// 예약정보
	function clsReserveInfo()
	{
		this._HTMLDom = null;
		this.infoData = null;
		
		this._init();
	}
	
	clsReserveInfo.prototype = {
		_init: function(){
			var $layer = $("dl.pop_offer");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.children().hide();
		}
		, setInfo: function(thisData){
			this.infoData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.children().show();
			$layer.find("dt:eq(0)").contents().eq(0).before(this.infoData["코스명"]).remove();
			$layer.find("dt:eq(0) span").html(this.infoData["홀명"]);
			$layer.find("dd:eq(0) p.offer_t").contents().eq(0).before(this.infoData["날짜"] + " " + this.infoData["요일"]).remove();
			$layer.find("dd:eq(0) p.offer_t span").html(this.infoData["시간"]);
			$layer.find("dd:eq(0) p.offer_price span").html(this.infoData["가격"]);
			
			document.objUtil.setWindowSize();
		}
	}
	
	function clsComm()
	{
		// 예약정보
		this.reserveInfo = null;
		this.reserveInfoRequest = null;
		
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){
			this.reserveInfoRequest = {
				"예약키": null
			}
			
			this.reserveInfo = {
				"코스명": null
				, "홀명": null
				, "날짜": null
				, "요일": null
				, "시간": null
				, "원가": null
				, "가격": null
				, "이벤트": null
			}
		}
		, setReserveInfoRequest: function(key, val){
			this.reserveInfoRequest[key] = val;
		}
		, getReserveInfo: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				thisClass.reserveInfo = {
					"코스명": "SKY72 하늘코스1"
					, "홀명": "15H"
					, "날짜": "2012. 04. 20"
					, "요일": "월요일"
					, "시간": "15:10"
					, "가격": "5,090,000"
				}
				
				document.objControl.finishReserveInfo();
			}, 1000);
		}
		, getReserveInfoData: function(){
			return this.reserveInfo;
		}
	}
	
	
	// 컨트롤
	function clsControl()
	{
		this.objComm = null;
		this.objReserveInfo = null;
		this.reserveKey = null;
		
		this._init();
	}
	
	clsControl.prototype = {
		_init: function(){
			if(!opener) self.close();
			if(!opener.document.objControl) self.close();
			
			this.reserveKey = opener.document.objControl.getReserveKey();
			
			//this.reserveKey = "001";
			
			if(!this.reserveKey) self.close();
			
			this.objComm = new clsComm();
			this.objReserveInfo = new clsReserveInfo();
			
			this._bind();
			
			document.objGlobal.spinStart("receiving...");
			this.objComm.setReserveInfoRequest("예약키", this.reserveKey);
			this.objComm.getReserveInfo();
		}
		, _bind: function(){
			var thisClass = this;
			
			// 닫기
			$("img[alt='취소']").parent("a").add("img[alt='close']").click(function(){
				self.close();
			});
			
			// 확인
			$("img[alt='예약신청']").parent("a").click(function(){
				opener.document.objControl.applyReserve(window);
			});
		}
		// 예약정보 완료
		, finishReserveInfo: function(){
			var thisData = this.objComm.getReserveInfoData();
				
			document.objGlobal.spinEnd();
			this.objReserveInfo.setInfo(thisData);
		}
	}
	
	document.objControl = new clsControl();
});